import os

def getenv_bool(name: str, default: bool = False) -> bool:
    v = os.environ.get(name)
    if v is None:
        return default
    return v.strip().lower() in ("1", "true", "yes", "on")

def getenv_int(name: str, default: int) -> int:
    try:
        return int(os.environ.get(name, default))
    except Exception:
        return default

# 基础路径（可按需使用）
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# 安全密钥
SECRET_KEY = os.environ.get("SECRET_KEY", "dev-secret-change-me")

# 数据库路径
DATABASE = os.environ.get("DATABASE", os.path.join("data", "content.db"))

# 上传目录与大小限制
UPLOAD_FOLDER = os.environ.get("UPLOAD_FOLDER", os.path.join("static", "uploads"))
MAX_CONTENT_LENGTH = getenv_int("MAX_CONTENT_LENGTH", 16 * 1024 * 1024)  # 默认 16MB

# 运行参数
DEBUG = getenv_bool("DEBUG", True)
HOST = os.environ.get("HOST", "0.0.0.0")
PORT = getenv_int("PORT", 5000)